#include "ActBehaviour.h"

/*
 * Rozhodovanie sa na najvyssej urovni.
 * Rozhoduje sa o tom, ci sa hra alebo je cas pozastaveny.
 */
void ActBehaviour::Behave()
{
#ifdef GOALIE
	world->me->bNeckSynchronization = false;
#endif

	//printf("\nActBehaviour::Behave()");

	//vektor vzdialenosti od lopty
	DATA_STORAGE.ballDiff = world->ball->pos - world->me->pos;
	//vzdialenost od lopty
	DATA_STORAGE.ballDistance = DATA_STORAGE.ballDiff.GetLength();
	
	if(DATA_STORAGE.ballDistance < (world->me->type->player_size + world->params->server->ball_size) )
	{
		DATA_STORAGE.ballDistance = world->me->type->player_size + world->params->server->ball_size;
	}

	//hra v mode playoff
	if(world->state->IsTimeStoped()) 
	{
		DATA_STORAGE.ballKickable = false;
		GetPlayOffBehaviour()->Behave();
	}
	//hra v mode playon
	else
	{
		//TXTN("%d: Acting", world->state->GetSimTime());
		DATA_STORAGE.ballKickable = DATA_STORAGE.ballDistance < world->params->server->ball_size + world->me->type->player_size + world->me->type->kickable_margin;
		GetPlayOnBehaviour()->Behave();
	}

	if(DATA_STORAGE.goalieCatch.goalieCatchBan > 0)
		DATA_STORAGE.goalieCatch.goalieCatchBan--;

	if((world->me->bNeckSynchronization) && (world->me->bSendTurnNeckTo))
		GetTurnNeckToBehaviour()->NeckSynchronizationWithVI(NEW_VI);
}
